const { createProxyMiddleware } = require('http-proxy-middleware');
const proxySettings = {
  // "/v1/store": {
  //   target: `http://${process.env.REACT_APP_NEXT_URL}:2021`,
  //   changeOrigin: true,
  // },
  '/aichat': {
    target: `http://112.132.229.234:7002`,
    changeOrigin: true,
    pathRewrite: { '^/aichat': '/aichat' },
  },
  '/api': {
    target: `https://next-dev.amcax.net`,
    changeOrigin: true,
    pathRewrite: { '^/api': '/api' },
  },
  '/nextmesh': {
    // target: `http://192.168.11.3:50005`,
    target: `https://next-dev.amcax.net`,
    changeOrigin: true,
    logLevel: 'debug',
  },
  '/app-cad/features.json': {
    target: 'http://localhost:8881',
    pathRewrite: { '^/app-cad': '/' },
  },
  // "/ws": {
  //   target: `http://${process.env.REACT_APP_NEXT_URL}`,
  //   ws: true,
  //   changeOrigin: true,
  //   logLevel: "debug",
  // },
  // "/corelist": {
  //   target: `http://${process.env.REACT_APP_NEXT_URL}:2025`,
  //   changeOrigin: true,
  // },
  // "/destroy": {
  //   target: `http://${process.env.REACT_APP_NEXT_URL}:2025`,
  //   changeOrigin: true,
  // },
};

module.exports = function (app) {
  for (const route in proxySettings) {
    app.use(route, createProxyMiddleware(route, proxySettings[route]));
  }
};
